var app = getApp()
Page({
  data: {
    cardNo: '',
    cardPwd: '',
    isPassword: true,
  },
  onLoad: function (options) {

  },

  changeEyeOpen: function () {
    var isPassword = this.data.isPassword
    if (isPassword == true) {
      isPassword = false
    }
    else {
      isPassword = true
    }
    this.setData({isPassword: isPassword})
  },
  scanCard: function () {
    var that = this
    wx.scanCode({
      success: function (res) {
        that.setData({
          cardNo: res.result
        })
      }
    })
  },
  goBack: function () {
    wx.navigateBack()
  },
  cardInput: function (e) {
    this.setData({
      cardNo: e.detail.value
    })
  },
  pwdInput: function (e) {
    this.setData({
      cardPwd: e.detail.value
    })
  },
  useCashCardAction: function () {
    if (this.data.cardNo === '' || this.data.cardPwd === '') {
      return
    }
    var url = '/yuanmai_we/mcake/order/cashCard/verify'
    var params = {
      cardNo: this.data.cardNo,
      cardPwd: this.data.cardPwd
    }
    app.request(url, params).then(this.useCashCardActionCallBack.bind(this))
  },
  useCashCardActionCallBack: function (res) {
    if (res.success) {
      app.globalData.tempCashCard = {
        cardNo: this.data.cardNo,
        cardPwd: this.data.cardPwd
      }
      wx.navigateBack()
    }
  }
})
